/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function getXMLHTTP()
{
    //alert("in getXMLHTTP()");

    var xmlHttpRequest = null;
    try
    {
        xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");

    }
    catch(e)
    {
        try
        {
            xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch(oc)
        {
            xmlHttpRequest = null;
        }
    }

    if(!xmlHttpRequest && typeof XMLHttpRequest != "undefined")
    {
        xmlHttpRequest = new XMLHttpRequest();
    }

    return xmlHttpRequest;
}


function checkLoginID()
{
    var wait= document.getElementById("wait");
    var loginID =  document.getElementById("loginID").value;
    if(loginID.length > 0)
    {
        if(checkSpecialChar("loginID"))
        {
            alert("Special characters not allowed.!!");
            document.getElementById("loginID").value = "";

        }
        else
        {
            document.getElementById("wait").innerHTML="<img src='/images/please_wait.gif'>";
            var xmlHttp = getXMLHTTP();
            //alert('test1 point');
            if(xmlHttp && xmlHttp.readyState != 0)
            {
                alert("Not ready for xmlHTTP call");
            }

            if(xmlHttp)
            {
                xmlHttp.open("GET", "/CheckLogonID?loginID="+loginID, true);

                xmlHttp.onreadystatechange = function()
                {
                    if (xmlHttp.readyState == 4)
                    {

                        var actualText = xmlHttp.responseText;
                        if(actualText == "Available")
                        {
                            document.getElementById("wait").innerHTML=""
                            document.getElementById("wait").innerHTML = "<p style='padding-top: 5px;color:Green'><span>"+actualText+"</span></p>"
                        }
                        else
                        {
                            document.getElementById("wait").innerHTML="<p style='padding-top: 5px;color:Red'><span>"+actualText+"</span></p>"
                            document.getElementById("loginID").value="";
                        }

                    }
                };
                xmlHttp.send(null);
            }
        }
    }
    else
    {
      //  document.getElementById("emailWait").innerHTML="";

    }
}

function checkSpecialChar(id)
{

    var iChars = "!#$%^&*()+=[]\\\';,/{}|\":<>?~";
    for (var i = 0; i <document.getElementById(id).value.length; i++)
    {
        if (iChars.indexOf(document.getElementById(id).value.charAt(i)) != -1)
        {
            return true;
        }

    }
    return false;
}

